package service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.Menu_dao;
import dto.MenuDto;
import entity.Menu;
import service.Menu_service;

@Service
public class Menu_service_impl implements Menu_service {

	@Autowired
	private Menu_dao menu_dao;
	
	@Override
	public boolean add_menu(Menu menu) {
		// TODO Auto-generated method stub
		return menu_dao.add_menu(menu);
	}

	@Override
	public boolean delete_menu(Integer id) {
		// TODO Auto-generated method stub
		return menu_dao.delete_menu(id);
	}

	@Override
	public boolean update_menu(Menu menu) {
		// TODO Auto-generated method stub
		return menu_dao.update_menu(menu);
	}

	@Override
	public Menu get_MenuById(Integer id) {
		// TODO Auto-generated method stub
		return menu_dao.get_MenuById(id);
	}

	@Override
	public List<Menu> get_childMenuByParentId(Integer parentId) {
		// TODO Auto-generated method stub
		return menu_dao.get_childMenuByParentId(parentId);
	}

	@Override
	public List<MenuDto> MenuList() {
		List<MenuDto> result=new ArrayList<>();
		List<Menu> list=menu_dao.MenuList();
		for (Menu menu : list) {
			MenuDto dto=new MenuDto();
			BeanUtils.copyProperties(menu, dto);
			dto.setpId(menu.getParentId());
			result.add(dto);
		}
		return result;
	}

	@Override
	public boolean batchDelete_menu(String[] ids) {
		if(ids!=null){
			Integer[] IDS=new Integer[ids.length];
			for(int i=0;i<ids.length;i++){
				IDS[i]=Integer.parseInt(ids[i]);
			}
			return menu_dao.batchDelete_menu(IDS);
		}
		return false;
	}

}
